const express = require('express');
const next = require('next');

const dev = process.env.NODE_ENV !== 'production';

// 创建next实例
const app = next({ dev });

// 获取路由处理功能
const handler = app.getRequestHandler();

// 等待next页面生成后执行
app.prepare().then(() => {
  const server = express();

  // 处理自定义页面
  server.get('/hello', (req, res) => {
    res.send('hello world');
  });

  // 其他交由next路由处理
  server.get('*', (req, res) => {
    handler(req, res);
  });

  server.listen(3000, () => console.log('custom server is listening on 3000 port'));
});